//
//  MemberRegionTableViewCell.m
//  location
//
//  Created by Dongxiang Xu on 2025/5/6.
//

#import "MemberRegionTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface MemberRegionTableViewCell ()

@property (nonatomic, strong) UIButton *img;
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UILabel *subLabel;
@property (nonatomic, strong) UIButton *bling;
@end

@implementation MemberRegionTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = RealWhiteColor;
        
        _img = [[UIButton alloc] initWithFrame:CGRectMake(16, 16, 60, 60)];
        _img.backgroundColor = WhiteColor;
        [_img.layer setCornerRadius:16];
        [self.contentView addSubview:_img];
        
        _label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_img.frame)+16, 22, SCREEN_WIDTH-CGRectGetMaxX(_img.frame)-82, 24)];
        _label.textColor = RealBlackColor;
        _label.font = MEDIUM_FONT(16);
        [self.contentView addSubview:_label];
        
        _subLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_img.frame)+16, CGRectGetMaxY(_label.frame)+4, SCREEN_WIDTH-CGRectGetMaxX(_img.frame)-82, 20)];
        _subLabel.textColor = GraryLightColor;
        _subLabel.font = DEFAULT_FONT(14);
        [self.contentView addSubview:_subLabel];
        
        _delete = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-84, 29, 34, 34)];
        _delete.hidden = YES;
        [_delete setImage:[UIImage imageNamed:@"region_bling_close"] forState:UIControlStateNormal];
        [self.contentView addSubview:_delete];
        [[_delete rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (self.MemberRegionDeleteBlock) {
                self.MemberRegionDeleteBlock();
            }
        }];        
        
        _bling = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-46, 29, 34, 34)];
        [_bling setImage:[UIImage imageNamed:@"region_bling_nor"] forState:UIControlStateNormal];
        [self.contentView addSubview:_bling];
        [[_bling rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (self.MemberRegionLaunchBlock) {
                self.MemberRegionLaunchBlock();
            }
        }];
    }
    return self;
}

- (void)loadWithInfo:(NSDictionary *)info
{
    if (![info[@"avatar"] isKindOfClass:[NSString class]] || [info[@"avatar"] length]==0) {
        [_img setImage:[UIImage imageNamed:@"region_icon_1"] forState:UIControlStateNormal];
    }else{
        [_img setImage:[UIImage imageNamed:info[@"avatar"]] forState:UIControlStateNormal];
    }
    _label.text = [NSString stringWithFormat:@"%@",info[@"name"]];
    _subLabel.text =  [NSString stringWithFormat:@"%@",info[@"address"]];
    _delete.hidden = ([info[@"groupAdminId"] integerValue]==[XDXShareInstance shareInstance].userId.integerValue || [info[@"adminId"] integerValue]==[XDXShareInstance shareInstance].userId.integerValue)?NO:YES;
    
    [_bling setImage:[UIImage imageNamed:[info[@"isLaunch"] boolValue]?@"region_bling":@"region_bling_nor"] forState:UIControlStateNormal];
}


@end
